<div id="content" class="span12">
    <h1>Users</h1>

    <div class="row">
        <div id="sidebar" class="span8">
            <div class="btn-toolbar">
                <div class="btn-group">
                    <?php echo CHtml::link('User Entry', '#dialog', array('class' => 'btn btn-info', 'data-toggle' => 'modal', 'onClick' => 'addUser();')); ?>
                </div>
            </div>
        </div>
        <div class="span12">
            <?php
            $this->widget('zii.widgets.grid.CGridView', array(
                'id' => 'data-grid',
                'dataProvider' => $dataProvider,
                //'filter' => $model,
                'columns' => array(
                    'username',
                    array(
                        'header' => 'Full Name',
                        'value' => 'ucwords($data->first_name . " " . $data->last_name)',
                    ),
                    'email',
                    array(
                        'name' => 'access_role',
                        'value' => 'User::model()->getAccessRoleList($data->access_role)',
                    ),
                    array(
                        'name' => 'group_id',
                        'header' => 'Group',
                        'value' => '$data->group->name',
                    ),
                ),
                'cssFile' => false,
                'itemsCssClass' => 'table',
                'summaryCssClass' => 'pull-right',
            ));
            ?>
        </div>    
    </div>
</div>

<script>
    function addUser() {
<?php
echo CHtml::ajax(array(
    'url' => array('user/create'),
    'data' => 'js:$(this).serialize()',
    'type' => 'post',
    'dataType' => 'json',
    'success' => 'function(data) {
                if (data.status == "failure")
                {
                    $("#dialog").html(data.div);
                    $("#dialog form").submit(addUser);
                }
                else
                {
                    $("#dialog").html(data.div);
                    setTimeout("$(\"#dialog\").dialog(\"hide\")",3000);
                }
            }'
));
?>
        return false;
    }
</script>